package com.bsj.pay.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsj.pay.dao.LogDao;
import com.bsj.pay.model.LogBean;
import com.bsj.pay.model.UserBean;
import com.bsj.pay.service.LogService;
import com.bsj.pay.util.HttpUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class LogServiceImpl implements LogService{
	
	@Autowired
	private LogDao dao;

	@Override
	public long insert(LogBean t) {
		// TODO Auto-generated method stub
		return dao.insert(t);
	}

	@Override
	public int deleteById(Long id) {
		// TODO Auto-generated method stub
		return dao.deleteById(id);
	}

	@Override
	public List<LogBean> queryList(LogBean t) {
		// TODO Auto-generated method stub
		return dao.queryList(t);
	}

	@Override
	public int update(LogBean t) {
		// TODO Auto-generated method stub
		return dao.update(t);
	}

	@Override
	public LogBean getById(Long Id) {
		// TODO Auto-generated method stub
		return dao.getById(Id);
	}

	@Override
	public long count(LogBean t) {
		// TODO Auto-generated method stub
		return dao.count(t);
	}

	@Override
	public PageInfo<LogBean> pageList(LogBean t, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		List<LogBean> list = dao.queryList(t);
		PageInfo<LogBean> pageInfo= new PageInfo<LogBean>(list);
		return pageInfo;
	}

	@Override
	public int removeById(Long id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<LogBean> queryAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addLog(HttpServletRequest request, String title) {
		// TODO Auto-generated method stub
		LogBean log = new LogBean();
		log.setIp(HttpUtil.getIpAddr(request));
		log.setCreate_time(System.currentTimeMillis() / 1000);
		log.setTitle(title);
		UserBean user = (UserBean) request.getSession().getAttribute("auser");
		if(user!=null)log.setUser_name(user.getAccount());
		else log.setUser_name("");
		log.setPath(request.getRequestURL().toString());
		dao.insert(log);
	}

	@Override
	public int removeByTime(long startTime, long endTime) {
		// TODO Auto-generated method stub
		return dao.removeByTime(startTime, endTime);
	}

}
